package vista;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.KeyListener;
import java.util.Date;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JSpinner;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.SpinnerListModel;

import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.border.LineBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class FacturaC extends javax.swing.JFrame {
	private JPanel jPanel1, jPanel2,  FondoF;
	private JSeparator jSeparator1, jSeparator2, jSeparator3, jSeparator4, jSeparator5,
					   jSeparator6, jSeparator7;
	private JButton bntBuscar, bntIncluir, bntGuardar, bntImprimir,
					bntCancelar, bntSalir;
	private JLabel SubTotal, iva, total;
	private JTextField txtcodProv, txtPrecioU, txtCantidad;
	private JScrollPane Pane1Ingredientes;
	private JTable ingredientes;
	private JComboBox comboIngrediente;
	private JLabel jLabel1, jLabel2, jLabel3, jLabel4, jLabel5, jLabel6, jLabel7, jLabel8, 
				   jLabel9, jLabel10, jLabel11, jLabel12, jLabel13, jLabel14;
	private JLabel fecha;
	private JLabel direccion;
	private JLabel NroControl;
	private JLabel razonsocial;

	int t = 0;
	boolean bool = false;
	private Object VAL[][];
	private final String[] MES = {"Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"};
	
	public FacturaC() {
		super();
		initGUI();
		getContentPane().setBackground(Color.white);
	}
	public Object [][] GetDatos()
	{
		return VAL;
	}
	
	public void VaciarDatos()
	{
		VAL = new Object[0][0];
		t = 0;
		bool = false;
	}
	
	public int N_Elementos()
	{
		return t;
	}
    
	 public void SetFecha(Date d)
	    {
		    String S[] = new Date().toString().split(" ");
	    	this.fecha.setText(d.getDay() + " " + MES[d.getMonth()-1] + " " + S[5]);
	    }
	 
	 public void addKeyListener(KeyListener kl)
		{
			txtCantidad.addKeyListener(kl);
		}
	 
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			getContentPane().setBackground(Color.white);
			this.setTitle("Factura de Compra");
			{
				jPanel1 = new JPanel();
				getContentPane().add(jPanel1).setBackground(Color.white);
				jPanel1.setBounds(13, 18, 623, 553);
				jPanel1.setLayout(null);
				jPanel1.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
				{
					jLabel1 = new JLabel();
					jPanel1.add(jLabel1);
					jLabel1.setText("Establecimiento de Comida Rapida JJA. C.A");
					jLabel1.setBounds(17, 35, 395, 24);
					jLabel1.setFont(new java.awt.Font("Purisa",0,16));
				}
				{
					jLabel3 = new JLabel();
					jPanel1.add(jLabel3);
					jLabel3.setText("Factura de Compra");
					jLabel3.setBounds(215, 114, 229, 26);
					jLabel3.setFont(new java.awt.Font("Purisa",1,20));
				}
				{
					ComboBoxModel jComboBox1Model = 
						new DefaultComboBoxModel(
								new String[] { "" });
					comboIngrediente = new JComboBox();
					jPanel1.add(comboIngrediente);
					comboIngrediente.setModel(jComboBox1Model);
					comboIngrediente.setBounds(104, 252, 155, 26);
				}
				{
					jLabel6 = new JLabel();
					jPanel1.add(jLabel6);
					jLabel6.setText("Ingrediente");
					jLabel6.setBounds(16, 252, 81, 26);
					jLabel6.setFont(new java.awt.Font("Dialog",0,14));
				}
				{
					jLabel7 = new JLabel();
					jPanel1.add(jLabel7);
					jLabel7.setText("Cantidad");
					jLabel7.setBounds(429, 252, 65, 26);
					jLabel7.setFont(new java.awt.Font("Dialog",0,14));
				}
				{
					jLabel8 = new JLabel();
					jPanel1.add(jLabel8);
					jLabel8.setText("Lista de Ingredientes");
					jLabel8.setBounds(229, 296, 191, 29);
					jLabel8.setFont(new java.awt.Font("Purisa",1,14));
				}
				{
					bntIncluir = new JButton();
					jPanel1.add(bntIncluir);
					bntIncluir.setText("I");
					bntIncluir.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagenes/aceptar.png")));
					bntIncluir.setFont(new java.awt.Font("Dialog",0,11));
					bntIncluir.setBounds(549, 249, 59, 31);
				}
				{
					Pane1Ingredientes = new JScrollPane();
					jPanel1.add(Pane1Ingredientes);
					Pane1Ingredientes.setBounds(13, 331, 595, 120);
				}
				{
					jSeparator1 = new JSeparator();
					jPanel1.add(jSeparator1);
					jSeparator1.setBounds(208, 141, 244, 10);
				}
				{
					jSeparator2 = new JSeparator();
					jPanel1.add(jSeparator2);
					jSeparator2.setBounds(2, 241, 619, 10);
				}
				{
					jSeparator3 = new JSeparator();
					jPanel1.add(jSeparator3);
					jSeparator3.setBounds(2, 287, 619, 10);
				}
				{
					txtCantidad = new JTextField();
					jPanel1.add(getTxtCantidad());
					txtCantidad.setBounds(497, 252, 41, 26);
				}
				{
					jLabel4 = new JLabel();
					jPanel1.add(jLabel4);
					jLabel4.setText("PrecioU");
					jLabel4.setBounds(277, 252, 57, 26);
					jLabel4.setFont(new java.awt.Font("Dialog",0,14));
				}
				{
					txtPrecioU = new JTextField();
					jPanel1.add(getTxtPrecioU());
					txtPrecioU.setBounds(335, 252, 77, 26);
				}
				{
					{
						total = new JLabel();
						jPanel1.add(total);
						total.setBounds(502, 519, 107, 23);
					}
					{
						iva = new JLabel();
						jPanel1.add(iva);
						iva.setBounds(502, 486, 107, 23);
					}
					{
						SubTotal = new JLabel();
						jPanel1.add(SubTotal);
						SubTotal.setBounds(502, 457, 107, 23);
					}
					{
						jSeparator4 = new JSeparator();
						jPanel1.add(jSeparator4);
						jSeparator4.setBounds(497, 509, 112, 10);
					}
					{
						jLabel11 = new JLabel();
						jPanel1.add(jLabel11);
						jLabel11.setText("Total:");
						jLabel11.setBounds(444, 515, 41, 23);
						jLabel11.setFont(new java.awt.Font("Dialog",0,14));
					}
					{
						jLabel10 = new JLabel();
						jPanel1.add(jLabel10);
						jLabel10.setText("I.V.A 12%");
						jLabel10.setBounds(415, 486, 71, 23);
						jLabel10.setFont(new java.awt.Font("Dialog",0,14));
					}
					{
						jLabel9 = new JLabel();
						jPanel1.add(jLabel9);
						jLabel9.setText("Sub-Total:");
						jLabel9.setBounds(414, 457, 76, 23);
						jLabel9.setFont(new java.awt.Font("Dialog",0,14));
					}
					{
						jLabel12 = new JLabel();
						jPanel1.add(jLabel12);
						jLabel12.setText("Cod. Proveedor");
						jLabel12.setBounds(16, 167, 113, 26);
						jLabel12.setFont(new java.awt.Font("Dialog",0,14));
					}
					{
						txtcodProv = new JTextField();
						jPanel1.add(getTxtcodProv());
						txtcodProv.setBounds(135, 167, 124, 26);
						txtcodProv.setFont(new java.awt.Font("Dialog",0,14));
					}
					{
						jSeparator5 = new JSeparator();
						jPanel1.add(jSeparator5);
						jSeparator5.setBounds(2, 160, 619, 10);
					}
					{
						jSeparator6 = new JSeparator();
						jPanel1.add(jSeparator6);
						jSeparator6.setBounds(2, 201, 619, 10);
					}
					{
						jLabel13 = new JLabel();
						jPanel1.add(jLabel13);
						jLabel13.setText("Razon Social:  ");
						jLabel13.setBounds(15, 209, 101, 26);
						jLabel13.setFont(new java.awt.Font("Dialog",0,14));
					}
					{
						razonsocial = new JLabel();
						jPanel1.add(getRazonsocial());
						razonsocial.setBounds(134, 209, 208, 26);
						razonsocial.setFont(new java.awt.Font("Dialog",1,14));
					}
					{
						jLabel14 = new JLabel();
						jPanel1.add(jLabel14);
						jLabel14.setText("Direccion:");
						jLabel14.setBounds(351, 209, 76, 26);
						jLabel14.setFont(new java.awt.Font("Dialog",0,14));
					}
					{
						direccion = new JLabel();
						jPanel1.add(getDireccion());
						direccion.setBounds(433, 209, 176, 26);
						direccion.setFont(new java.awt.Font("Dialog",1,14));
					}
					{
						bntBuscar = new JButton();
						jPanel1.add(bntBuscar);
						bntBuscar.setText("B");
						bntBuscar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagenes/buscar1.png")));
						bntBuscar.setDoubleBuffered(false);
						bntBuscar.setBounds(271, 164, 57, 33);
						bntBuscar.setFocusCycleRoot(false);
					}
					{
						FondoF = new JPanel();
						jPanel1.add(FondoF);
						FondoF.setBounds(412, 0, 211, 94);
						FondoF.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
						FondoF.setLayout(null);
						{
							fecha = new JLabel();
							FondoF.add(fecha);
							fecha.setFont(new java.awt.Font("Purisa",1,14));
							
							fecha.setBounds(240, 56, 89, 26);
						}
						{
							jLabel2 = new JLabel();
							FondoF.add(jLabel2);
							jLabel2.setText("Fecha:");
							jLabel2.setBounds(14, 23, 50, 25);
							jLabel2.setFont(new java.awt.Font("Purisa",1,14));
						}
						{
							jLabel5 = new JLabel();
							FondoF.add(jLabel5);
							jLabel5.setText("N° de Control:");
							jLabel5.setFont(new java.awt.Font("Purisa",1,12));
							jLabel5.setBounds(14, 57, 103, 21);
						}
						{
							NroControl = new JLabel();
							FondoF.add(NroControl);
							NroControl.setBounds(129, 55, 48, 25);
							NroControl.setText("Factura N° de Control");
							NroControl.setFont(new java.awt.Font("Purisa",1,14));
						}
					}
					{
						jSeparator7 = new JSeparator();
						jPanel1.add(jSeparator7);
						jSeparator7.setBounds(1, 92, 412, 10);
					}
					fecha.setBounds(67, 21, 138, 24);
					fecha.setFont(new java.awt.Font("Purisa",1,14));
				}
			}
			{
				jPanel2 = new JPanel();
				getContentPane().add(jPanel2);
				jPanel2.setBounds(57, 585, 548, 56);
				jPanel2.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
				jPanel2.setLayout(null);
				{
					bntGuardar = new JButton();
					jPanel2.add(bntGuardar);
					bntGuardar.setText("Guardar");
					bntGuardar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagenes/aceptar.png")));
					bntGuardar.setFont(new java.awt.Font("Dialog",0,11));
					bntGuardar.setBounds(10, 8, 121, 39);
				}
				{
					bntImprimir = new JButton();
					jPanel2.add(bntImprimir);
					bntImprimir.setText("Imprimir");
					bntImprimir.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagenes/imprimir.png")));
					bntImprimir.setBounds(147, 8, 121, 39);
					bntImprimir.setFont(new java.awt.Font("Dialog",0,11));
				}
				{
					bntCancelar = new JButton();
					jPanel2.add(bntCancelar);
					bntCancelar.setText("Cancelar");
					bntCancelar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagenes/eliminar.png")));
					bntCancelar.setFont(new java.awt.Font("Dialog",0,11));
					bntCancelar.setBounds(288, 8, 126, 39);
				}
				{
					bntSalir = new JButton();
					jPanel2.add(bntSalir);
					bntSalir.setText("Salir");
					bntSalir.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagenes/salir1.png")));
					bntSalir.setBounds(433, 8, 94, 39);
				}
			}
			pack();
			this.setSize(652, 680);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	public JLabel getFecha() {
		return fecha;
	}
	
	public JLabel getNroControl() {
		return NroControl;
	}
	
	public JTextField getTxtCantidad() {
		return txtCantidad;
	}
	
	public JTextField getTxtPrecioU() {
		return txtPrecioU;
	}
	
	public JLabel getSubTotal() {
		return SubTotal;
	}
	
	public JLabel getIva() {
		return iva;
	}
	
	public JLabel getTotal() {
		return total;
	}
	
	public JTable getIngredientes() {
		return ingredientes;
	}

	public JComboBox getComboIngrediente() {
		return comboIngrediente;
	}

	public void setComboIngrediente(String str) {
		ComboBoxModel modelo = new DefaultComboBoxModel(str.split(","));
		comboIngrediente.setModel(modelo);
	}
	
	public void setNumeroC(int n){
		NroControl.setText("000"+n);
	}
	
	public void setTxtCantidad(int n){
		txtCantidad.setText(""+n);
	}
	
	public void setTxtPrecioU(String x){
		txtPrecioU.setText(x);
	}
	
	public void setSubTotal(String x) {
		SubTotal.setText(x);
	}
	
	public void setTxtCodProv(String x){
		txtcodProv.setText(x);
	}
	
	public void setRazonSocial(String x){
		razonsocial.setText(x);
	}
	
	public void setDireccion(String x){
		direccion.setText(x);
	}
	
	public void setIva(String x) {
		iva.setText(x);
	}

	public void setTotal(String x) {
		total.setText(x);
	}

	public void Anadir(List<Object>L)
	{
		
		Object[][]aux  = new Object[++t][4];
		for(int i = 0;i < t-1;i++)
			for(int j = 0;j < 4;j++)
				aux[i][j] = VAL[i][j];

		
		for(int i = 0;i < 4;i++)
			aux[t-1][i] = L.get(i);
		
		
		VAL  = new Object[t][4];
		for(int i = 0;i < t;i++)
			for(int j = 0;j < 4;j++)
				VAL[i][j] = aux[i][j];
		t = bool == true ? t : 0;
		bool = true;
		CargarTabla();
	}
	
	public void EnabledBntGuardar(boolean x)
	{
		bntGuardar.setEnabled(x);
	}
	
	public void CargarTabla()
	{
		TableModel jTable1Model = 
		new DefaultTableModel
		(VAL,new String[] { "  Ingrediente  ", " Precio "," Cantidad "," Sub Total "  });
		
		ingredientes = new JTable();
		Pane1Ingredientes.setViewportView(ingredientes);
		ingredientes.setModel(jTable1Model);
		ingredientes.setBounds(13, 332, 592, 95);
		ingredientes.setShowVerticalLines(false);
		ingredientes.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
		ingredientes.setToolTipText("");
		ingredientes.setOpaque(false);

	}
	public void addListener(ActionListener actionListener) {
		this.bntBuscar.addActionListener(actionListener);
		this.bntIncluir.addActionListener(actionListener);
		this.bntGuardar.addActionListener(actionListener);
		this.bntCancelar.addActionListener(actionListener);
		this.bntSalir.addActionListener(actionListener);
	}
	public void mostrarMensaje(String mensaje) {
		JOptionPane.showMessageDialog(this, mensaje);
	}
	
	public JTextField getTxtcodProv() {
		return txtcodProv;
	}
	
	public JLabel getRazonsocial() {
		return razonsocial;
	}
	
	public JLabel getDireccion() {
		return direccion;
	}
}
